﻿using System;
using System.Web;
using viPage.Classes;
using viPage.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Installer;

public partial class Admin_Pages_viPage_Pages : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void NEW_PAGE_Click(object sender, EventArgs e)
    {
        Response.Redirect(SystemMenu.CallPage("viPage", "AddPage"));
    }

    public string GetLink(int pageid)
    {
        return SystemMenu.CallPage("viPage", "EditPage", "PageId", pageid.ToString());        
    }

    protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeletePage")
        {
            int pageId = Convert.ToInt32(e.CommandArgument);
            viPageController.DeletePage(pageId);
            Response.Redirect(Request.RawUrl);
        }
        if (e.CommandName == "PreviewPage")
        {
            int pageId = Convert.ToInt32(e.CommandArgument);
            viPageInfo page = viPageController.GetPage(pageId);
            if (page == null)
                Response.Redirect(Request.RawUrl);
            Response.Redirect(WebRoots.GetWebRoot + PluginController.GetInstalledPlugin("viPage").UrlSeparator + "/" + HttpUtility.UrlEncode(page.Name) + ".aspx");            
        }
        if (e.CommandName == "DesignPage")
        {
            int pageId = Convert.ToInt32(e.CommandArgument);
            viPageInfo page = viPageController.GetPage(pageId);
            if (page == null)
                Response.Redirect(Request.RawUrl);
            Response.Redirect(WebRoots.GetWebRoot + "Designer.aspx?PageId=" + page.WebPageId);
        }
    }
}